<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
lang="utf-8" xml:lang="utf-8">
<head>
<title>Lab3: Parser</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2010-05-17 12:45:12 "/>
<meta name="author" content="Zhuang Zhong"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link rel="stylesheet" href="style/base.css"  type="text/css" />
<script type="text/javascript">
<!--/*--><![CDATA[/*><!--*/
 function CodeHighlightOn(elem, id)
 {
   var target = document.getElementById(id);
   if(null != target) {
     elem.cacheClassElem = elem.className;
     elem.cacheClassTarget = target.className;
     target.className = "code-highlighted";
     elem.className   = "code-highlighted";
   }
 }
 function CodeHighlightOff(elem, id)
 {
   var target = document.getElementById(id);
   if(elem.cacheClassElem)
     elem.className = elem.cacheClassElem;
   if(elem.cacheClassTarget)
     target.className = elem.cacheClassTarget;
 }
/*]]>*///-->
</script>
</head>
<body>
<div id="content">

<h1 class="title">Lab3: Parser</h1>



<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Introduction </h2>
<div class="outline-text-2" id="text-1">

<p>This assignment requires you to write a parser for our <a href="spec.html"><b>C programming language</b></a>.
</p>
</div>

</div>

<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Instruction </h2>
<div class="outline-text-2" id="text-2">

<dl>
<dt>To Run Lab3</dt><dd>

<ol>
<li>
<a href="lab3.zip">Download</a> this package, and extract somewhere
</li>
<li>
In command-line, enter the path and run:
</li>
<li>
ml-yacc c.grm
</li>
<li>
ml-lex c.lex
</li>
<li>
MLton: mlton lab3.mlb and Run lab3 like "lab3 test.c". 
</li>
<li>
SML/NJ: sml sources.cm and Run lab3 like Main.parse_file "test.c".
</li>
</ol>
</dd>
<dt>File Description</dt><dd>

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" /><col align="left" />
</colgroup>
<tbody>
<tr><td>c.lex</td><td>ml-lex file</td><td>*</td></tr>
<tr><td>c.grm</td><td>ml-yacc file</td><td>**</td></tr>
<tr><td>main.sml</td><td>call the parser</td><td></td></tr>
<tr><td>sources.cm</td><td>for SML/NJ</td><td></td></tr>
<tr><td>lab3.mlb</td><td>for MLton</td><td></td></tr>
<tr><td>test.c</td><td>a test file</td><td></td></tr>
<tr><td>LICENSE</td><td>License of our code</td><td></td></tr>
</tbody>
</table>

</dd>
<dt>To Do Lab3</dt><dd>

<ol>
<li>
Read ML Yacc <a href="http://www.smlnj.org/doc/ML-Yacc/index.html">Manual</a>
</li>
<li>
Refer to <a href="spec.html">specification</a> of our C language
</li>
<li>
You need to finish "<b>c.lex</b>" and "<b>c.grm</b>"
</li>
<li>
You can copy a lot of code in "c.lex" from Lab2.
</li>
<li>
Finish "c.grm". In Lab3, you don't need to add semantic rules. If your "c.grm" is correct, parser will return "Success!"
</li>
</ol>
</dd>
</dl>




<pre class="example">program : function_protos struct_decls functions ()
function_protos : type id LPAREN var_decls RPAREN SEMICOLON ()
....
</pre>




</div>

</div>

<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Note </h2>
<div class="outline-text-2" id="text-3">

<p>Lab4 will be quite easy if you do Lab3 well! 
</p>




</div>
</div>
<div id="postamble">
</div>
</div>
</body>
</html>
